﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace WebSystem
{
    public partial class MClaUpd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] == "1")
            {
                Page.Theme = "1";
            }
            else if (Session["Theme"] == "3")
            {
                Page.Theme = "3";
            }

            else
            {
                Page.Theme = "2";
            }
        }
        protected void Button7_Click(object sender, EventArgs e)
        {
            Response.Redirect("MCla.aspx");
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaAdd.aspx");
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaDel.aspx");
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            Response.Redirect("MClaUpd.aspx");
        }

        protected void btn_Click(object sender, EventArgs e)
        {
            //string strCn = "server=pc.hstc.cn;database=dhd2014115121;uid=2014115121;pwd=19960404";
            //SqlConnection cn = new SqlConnection(strCn);
            //try
            //{
            //    cn.Open();
            //    string strSql = "UPDATE  Course SET Cno = N' + this.txtCno.Text +', Age = 20 WHERE   (No = N'2014112110')";
            //    SqlCommand cmd = new SqlCommand(strSql, cn);
            //    int iUpd = cmd.ExecuteNonQuery();
            //    if (iUpd < 1)
            //    {
            //        this.lblInfo.Text = "更新失败！";
            //    }
            //    else
            //    {
            //        this.lblInfo.Text = "更新" + iUpd.ToString() + "条记录！";
            //    }
            //}
            //catch (Exception ex)
            //{
            //    this.lblInfo.Text = ex.Message;
            //}
            //finally
            //{
            //    cn.Close();
            //}
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            //txtCname.Text = "";
            //txtCno.Text = "";
            //txtCre.Text = "";
            //txtTno.Text = "";
        }

      

        protected void btnUpd_Click(object sender, EventArgs e)
        {
            //String strCn = "Server=pc.hstc.cn;database=dhd2014112110;uid=2014112110;pwd=19941225";
            //SqlConnection cn = new SqlConnection(strCn); //建对象
            //try
            //{
            //    cn.Open();//打开连接
            //    string strCno = this.txtCno.Text;
            //    //忽略检测范围
            //    string strSql = "SELECT   Cname,Credit,Tno FROM      Course  WHERE   (Cno = N'" + strCno + "')";
            //    //string strSql = "select * from Student";
            //    SqlCommand cmd = new SqlCommand(strSql, cn);
            //    SqlDataReader dr = cmd.ExecuteReader();
            //    if (dr.Read())
            //    {
            //        this.txtCname.Text = dr["Cname"].ToString();
            //        this.txtCre.Text = dr["Credit"].ToString();
            //        this.txtTno.Text = dr["Tno"].ToString();
            //    }
            //    //this.GridView1.DataSource = dr;
            //    //this.GridView1.DataBind();
            //    //dr.Close();
            //}
            //catch (Exception ex)
            //{
            //    this.lblInfo.Text = ex.Message;//将异常信息显示在label中
            //}
            //finally
            //{
            //    cn.Close();
            //}
        }

        protected void btnOut_Click(object sender, EventArgs e)
        {
            String strCn = "Server=pc.hstc.cn;database=dhd2014115121;uid=2014115121;pwd=19960404";
            SqlConnection cn = new SqlConnection(strCn); //建对象
            try
            {
                cn.Open();//打开连接
                string strCno = this.txtCno.Text;
                //忽略检测范围
                string strSql = "SELECT   Cname,Credit,Tno FROM      Course  WHERE   (Cno = N'" + strCno + "')";
                //string strSql = "select * from Student";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    this.txtCname.Text = dr["Cname"].ToString();
                    this.txtCre.Text = dr["Credit"].ToString();
                    this.txtTno.Text = dr["Tno"].ToString();
                }
                //this.GridView1.DataSource = dr;
                //this.GridView1.DataBind();
                //dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;//将异常信息显示在label中
            }
            finally
            {
                cn.Close();
            }
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            txtCname.Text = "";
            txtCno.Text = "";
            txtCre.Text = "";
            txtTno.Text = "";
            lblInfo.Text = "";
        }

        protected void btnUpd_Click1(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014115121;uid=2014115121;pwd=19960404";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                //string strSql = "UPDATE  Student SET Name = N'计算机学院', Age = 20 WHERE   (No = N'2014112101')";
                string strSql = "UPDATE  Course SET         Cname = N'" + this.txtCname.Text + "', Credit = " + this.txtCre.Text + ",Tno = " + this.txtTno.Text + " WHERE   (Cno = N'" + this.txtCno.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "更新失败！";
                }
                else
                {
                    this.lblInfo.Text = "更新" + iUpd.ToString() + "条记录！";
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}